home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / utter10.zip / UTTER.PAS < prev   
Pascal/Delphi Source File  |  1994-06-20  |  36KB  |  917 lines

  1. PROGRAM Utter;
  2.  
  3. (* UTTER 1.0, Copyright (c) 1994, by Jody R. Cairns
  4.  
  5.    UTTER displays quotes that are stored in a separate ASCII data file, by
  6.    default called UTTER.DAT, although a different file can be used if
  7.    specified on the command-line. All quotes must end with a tilde (~).
  8.    The quote file may be edited using the /E option. There are many more
  9.    options (and more to come) including: display random quote, prompt
  10.    user after quote is displayed, change video output, show number of
  11.    quotes in quote file, etc.
  12.  
  13.    The source to this program (this file) is free to the public domain with
  14.    the condition that I am notified of any modifications made to this
  15.    program, and the executable of the MODIFIED program is NOT distributed
  16.    without my permission (i.e. Don't pull a fast one like making a few
  17.    changes to the source, compiling it, and saying you wrote it.).  Otherwise,
  18.    the source and executable are free to those who want it.
  19.  
  20.    It would be very much appreciated if any code used from this program is
  21.    credited to me (bearing in mind that I take absolutely no responsibility
  22.    for the results or misuse of the execution or use of said code).
  23.  
  24.    Main Algorithm
  25.    --------------
  26.       1) Check if valid DOS version (must be >= 3.0).
  27.       2) Get executable's filename and residing directory.
  28.       3) Process command-line for options.
  29.       4) Check if data file containing quotes exists.
  30.       5) Check if index file for data file exists and is valid.
  31.       6) Read index file to get old data file time-stamp.
  32.       7) Compare old data file's time-stamp with current data file's time-stamp.
  33.       8) Update index file if any discrepancies.
  34.       9) Execute options if specified.
  35.      10) Seek into proper location of data file for quote (determined
  36.          from location read from index file).
  37.      11) Read and display quote.
  38.      12) Update index file with next quote to be displayed location.
  39.      13) Close files.
  40.  
  41.    See PROCEDURE DisplayHelp for more information about options available
  42.    and the data file format.
  43.  
  44.    See PROCEDURE UpdateIndexFile for information on the format of the
  45.    index file(s).
  46.  
  47.    NOTE: this program is not very modular due to the speed factor. I wanted
  48.          to make this as fast as possible without adding much assembly code
  49.          and still have sufficient error-checking.  Too many procedures
  50.          would have slowed it down (I timed it). So, please excuse this
  51.          programming oversight; it was done for speed. However, you will
  52.          notice I could have been LESS modular; code size was a factor, too.
  53.  
  54.    UTTER.PAS was written and compiled using TURBO PASCAL 6.0 and tested
  55.    on a variety of Personal Computers, from 8086s to 80486s.
  56.  
  57.    If you find ANY bugs, or have any suggestions or ideas I'd be happy to
  58.    hear from you.  Please don't hesitate to contact me for any information.
  59.    I have more utilites in the works, all DOS-based. Here's my address:
  60.  
  61.    Jody R. Cairns
  62.    P.O. Box 5991
  63.    St. John's, NF
  64.    Canada
  65.    A1C 5X4
  66.  
  67.    e-mail: jodyc@cs.mun.ca
  68.  
  69.                                                                           *)
  70.  
  71. (* Compiler directives follow: *)
  72.  
  73. {$M 5120,0,0}    (* Memory requirements: 5 KB for stack, 0 KB for heap *)
  74.  
  75. {$I-}            (* I/O checking off                 *)
  76. {$R-}            (* Range checking off               *)
  77. {$S-}            (* Stack checking off               *)
  78. {$X-}            (* Extended syntax off              *)
  79. {$V-}            (* Strict VAR-string checking off   *)
  80. {$B-}            (* Short-circuit boolean evaluation *)
  81. {$D-}            (* Debug information off            *)
  82. {$L-}            (* Local debug information off      *)
  83. {$E-}            (* 8087 emulation off               *)
  84. {$N-}            (* 8087/80287 code generation off   *)
  85. {$G-}            (* 80286 code generation off        *)
  86. {$F-}            (* Force far calls off              *)
  87. {$A+}            (* Word align data                  *)
  88. {$O-}            (* Overlays not allowed             *)
  89.  
  90.  
  91. USES
  92.   DOS, CRT;
  93.  
  94.  
  95. LABEL
  96.   EndLoop1,      (* Used for goto statements *)
  97.   EndLoop2;
  98.  
  99.  
  100. CONST
  101.   Title         = 'UTTER 1.0, Copyright (c) 1994, Jody R. Cairns';
  102.  
  103.   EndOfQuote    = '~';        (* End of quote indicator                  *)
  104.   IndexExt      = '.IDX';     (* extension of index file                 *)
  105.   ESC           = #27;        (* ASCII code for <ESC> key                *)
  106.   BufferSize    = 1024 * 61;  (* Maximum size of buffer                  *)
  107.   MaxWord       = 65535;      (* Largest possible word value             *)
  108.   MaxSeconds    = 60;         (* Maximum # of seconds for /P option      *)
  109.  
  110.  
  111. TYPE
  112.   NumStr     = string[11];                    (* Longint type converted to string *)
  113.   IDXFile    = file of longint;               (* Format of index file             *)
  114.   BufferType = ARRAY[1..BufferSize] OF char;  (* Buffer used for reading quotes   *)
  115.  
  116.  
  117. CONST
  118.   UpdateFile   : boolean = FALSE;  (* Update index file                    *)
  119.   ShowNumber   : boolean = FALSE;  (* Show number of quotes in quote file  *)
  120.   GetRandom    : boolean = FALSE;  (* Get random quote from quote file     *)
  121.   TitleNotShown: boolean = TRUE;   (* Program name has been displayed      *)
  122.   InvokeEditor : boolean = FALSE;  (* Invoke editor to edit file of quotes *)
  123.   DoPrompts    : boolean = TRUE;   (* Display warning prompts              *)
  124.   KeyPause     : boolean = FALSE;  (* Pause with key prompt after quote    *)
  125.   MousePause   : boolean = FALSE;  (* Pause with mouse prompt after quote  *)
  126.   Pause        : boolean = FALSE;  (* Pause for some seconds after quote   *)
  127.   Editor       : PathStr = 'EDIT'; (* Default editor name                  *)
  128.   CurrRow      : byte    = 0;      (* Current row number of screen         *)
  129.   PauseMilSecs : word    = 2000;   (* # of milliseconds to pause for /P    *)
  130.   Prompt       : ComStr  = #13#10'Press any key to continue...';
  131.  
  132.  
  133. VAR
  134.   DataFile  : file;       (* File containing quotes                          *)
  135.   IndexFile : IDXFile;    (* Index file for DataFile                         *)
  136.   Buffer    : BufferType; (* Buffer used for reading in quotes               *)
  137.   Dir       : DirStr;     (* Directory that contains UTTER.EXE               *)
  138.   Name      : NameStr;    (* Name of executing program                       *)
  139.   Ext       : ExtStr;     (* Extension of file that contains quotes          *)
  140.   TmpStr,                 (* Used for option /P[x] -> converted number       *)
  141.   Param     : ComStr;     (* Paramater on command-line                       *)
  142.   EditorPath,             (* Full path name of editor                        *)
  143.   DataPath  : PathStr;    (* Full PATH location of file that contains quotes *)
  144.   LongIntVar,             (* Used for the /P option in val procedure         *)
  145.   DataTime,               (* Current time stamp of file containing quotes    *)
  146.   OldDataTime,            (* Old time stamp of file containing quotes        *)
  147.   StartPos  : longint;    (* Index of quotes in Datafile                     *)
  148.   RecsRead,               (* # of records (chars) read into Buffer           *)
  149.   I, J,                   (* Indices and other stuff                         *)
  150.   Code      : word;       (* Temporary storage                               *)
  151.   Ch        : char;       (* Character pressed during prompt                 *)
  152.   NumRows   : byte;       (* Number of rows on screen                        *)
  153.   Reg       : registers;  (* CPU registers                                   *)
  154.  
  155.  
  156. (*****************************************************************************)
  157. (*****************************************************************************)
  158.  
  159.  
  160. FUNCTION KeyPressed: boolean; assembler;
  161. (* Returns TRUE if a key is pressed. *)
  162.   ASM
  163.     mov ah, 11h     (* Report whether character is ready *)
  164.     int 16h         (* Call Keyboard function            *)
  165.     mov al, 0       (* Assume FALSE                      *)
  166.     jz  @Done       (* Zero flag set? Yes, then no input *)
  167.     inc